// AssemblyScript: module.ts

// Import for array memory handling
declare function abort(message: string, fileName: string, line: i32, column: i32): void;

// Simple variable operation
export function add(a: i32, b: i32): i32 {
    return a + b;
}

// Sum of an array
export function sumArray(pointer: usize, length: i32): i32 {
  let sum: i32 = 0;
  for (let i = 0; i < length; i++) {
      sum += load<i32>(pointer + i * sizeof<i32>()); // 按内存偏移读取每个元素
  }
  return sum;
}

// Sum of object-like structure
export function sumObject(pointer: usize): i32 {
    // Assume pointer points to an array of two i32 values
    let a = load<i32>(pointer);
    let b = load<i32>(pointer + sizeof<i32>());
    return a + b;
}
